import React, {useState} from "react";
import {getResult} from "@/services/ant-design-pro/attribute";
import {ProTable} from "@ant-design/pro-table";
import {defaultPagination, paginationTool} from "@/utils/util";
import {useMount, useRequest} from "ahooks";
import {findByWalletPageLogList} from "@/services/ant-design-pro/log";

const getAttr = async (key: string) => {
  return await getResult ( key, 1 );
};
const columns = [{
  title: "编号",
  key: "id",
  dataIndex: "id",
  search: false,
},{
  title: "用户姓名",
  key: "name",
  dataIndex: "name",
  search: true,

}, {
  title: "动作",
  key: "state",
  dataIndex: "state",
  search: true,
  valueType: "select",
  valueEnum: await getResult ( "usersblancewithdrawaltype", 0 ),
  //usersblancewithdrawaltype
}, {
  title: "操作帐户",
  key: "type",
  dataIndex: "type",
  valueType: "select",
  valueEnum: await getResult ( "userswithdrawaltype", 0 ),
  search: true,

}, {
  title: "操作金额",
  key: "price",
  dataIndex: "price",
  valueType: "money",
  search: false,
}, {
  title: "当前余额",
  key: "balance",
  dataIndex: "balance",
  valueType: "money",
  search: false,
}, {
  title: "详细说明",
  key: "remark",
  dataIndex: "remark",
  search: false,
}, {
  title: "申请时间",
  key: "create_date",
  dataIndex: "create_date",
  valueType: 'dateTime',
  search: false
}, {
  title: "下单人",
  key: "orderUserName",
  dataIndex: "orderUserName",
  search: false,
}, {
  title: "操作员",
  key: "operatorName",
  dataIndex: "operatorName",
  search: false,
}]


const Page: React.FC = () => {
  const [pagination, setPagination] = useState<API.Pagination> ( defaultPagination () );
  const {
    run: fetchByPageList,
    refresh,
    data: dataList,
    loading,
  } = useRequest ( findByWalletPageLogList, {
    debounceWait: 100,
    manual: true,
  } );

  useMount ( () => {
    fetchByPageList ();
  } );

  return (<>     <ProTable loading={loading}
  pagination={paginationTool ( pagination, dataList?.data?.total, (data1: API.Pagination) => {
    console.log ( data1 )
    setPagination ( data1 );
    fetchByPageList ( {...data1} );
  } )}  columns={columns}
                           onSubmit={(params) => {
                             fetchByPageList ( params );
                             console.log ( 'onSubmit', params );
                           }}
  dataSource={dataList?.data?.list}/></>)

}

export default Page
